package com.jy.rhin.infra.cda.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.jy.rhin.infra.cda.zyzy.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author dhl
 * @date 2023/2/10
 * @Description 住院摘要
 */
@Mapper
@Repository
public interface ZhuYuanZhaiYaoMapper extends BaseMapper<Object> {

    @Select("select id, ZHUYUANJZLSH,                             \n" +
            "            ZHENGZHUANGMC,                           \n" +
            "            GENGXINSJ,                           \n" +
            "            BINGANHAO,                           \n" +
            "            RUYUANSJ,                           \n" +
            "            CHUYUANSJ,                          \n" +
            "            ZHUZHIYSDM,                             \n" +
            "            ZHUZHIYSXM,                            \n" +
            "            YILIAOJGDM,                               \n" +
            "            ZHENGZHUANGDM,                               \n" +
            "            BINGQINGZGDM,                            \n" +
            "            ZHENGJIANHM,                            \n" +
            "            RUYUANKSMC,                            \n" +
            "            ZHENGZHUANGKSSJ,                            \n" +
            "            ZHENGZHUANGCXSJ,                            \n" +
            "            patientId                            \n" +
            "    from YL_ZHUYUANJZJL  ${ew.customSqlSegment}                        ")
    ZhuYuanInfoVo queryZhuYuanInfo(@Param(Constants.WRAPPER) QueryWrapper<ZhuYuanInfoVo> queryWrapper);

    @Select("select JIUZHENLSH,JIANCHAXMDM,JIANCHAXMMC,JIANCHABGJGSJ,JIANCHABGJGZD,YICHANGBZ from YL_JIANCHABG ${ew.customSqlSegment}")
    List<JianChaInfoVo> queryJianChaList(@Param(Constants.WRAPPER) QueryWrapper<JianChaInfoVo> queryWrapper);

    @Select("select a.JIUZHENLSH, a.JIANYANBGID, b.JIANYANXMDM, b.JIANYANXMMC, b.JIANYANJG, b.JIANYANJGYCBZ       \n" +
            "    from YL_JIANYANBG a left join yl_jianyanbgmx b  on a.JIANYANBGID = b.JIANYANBGID and a.YILIAOJGDM = b.YILIAOJGDM and a.YUANQUID = b.YUANQUID  ${ew.customSqlSegment}    ")
    List<JianYanInfoVo> queryJianYanList(@Param(Constants.WRAPPER) QueryWrapper<JianChaInfoVo> queryWrapper);
//todo 删除不需要的select
//    @Select("select HUANZHECRXBZ zhuanZhenBZ,ZHUANZHENBZ from YL_RUYUANJL ${ew.customSqlSegment}")
//    @Select("select ZHUANKEMD zhuanZhenYY,ZHUANRUSJ zhuanZhenRQ,ZHUANRUKSDM zhuanZhenKSDM,ZHUANRUKSMC zhuanZhenKSMC,YILIAOJGDM zhuanZhenJGDM,ZHENLIAOGCMS jianKangWYPG from YL_ZHUANKEJILU ${ew.customSqlSegment}")
//    ZhuanZhenInfoVo queryZhuanZhenInfo(@Param(Constants.WRAPPER) QueryWrapper<ZhenDuanInfoVo> queryWrapper);

    @Select("select a.RUYUANHQZRQ zhenDuanSJ, a.ZHENDUANMC, a.ZHENDUANBM zhenDuanDM, \n" +
            "b.HUANZHECRXBZ chuanRanXBZ, c.SIWANGZDBM siWangZDDM,c.SIWANGZDMC siWangZDMC,c.SIWANGSJ from YL_BINGANSYZD a \n" +
            "LEFT JOIN yl_ruyuanjl b ON a.ZHUYUANJZLSH = b.ZHUYUANJZLSH and a.YILIAOJGDM = b.YILIAOJGDM and a.YUANQUID = b.YUANQUID \n" +
            "LEFT JOIN yl_siwangjilu c ON a.ZHUYUANJZLSH = b.ZHUYUANJZLSH and a.YILIAOJGDM = c.YILIAOJGDM and a.YUANQUID = c.YUANQUID ${ew.customSqlSegment}")
    ZhenDuanInfoVo queryZhenDuan(@Param(Constants.WRAPPER) QueryWrapper<ZhenDuanInfoVo> queryWrapper);

    @Select("SELECT HUIZHENDLSH,HUIZHENYY,HUIZHENYJ,HUIZHENRQ,HUIZHENYSXM,SHENQINGKSMC,HUIZHENYSSZJGDM,HUIZHENYSSZJGMC FROM YL_HUIZHENJILU ${ew.customSqlSegment} ")
    HuiZhenInfoVo queryHuiZhen(@Param(Constants.WRAPPER) QueryWrapper<HuiZhenInfoVo> queryWrapper);

    @Select("SELECT a.RUYUANQK,b.JINHOUZLFA FROM yl_cyxj a LEFT JOIN yl_zhiliaojl b ON a.ZHUYUANJZLSH=b.ZHUYUANJZLSH  and a.YILIAOJGDM = b.YILIAOJGDM and a.YUANQUID = b.YUANQUID ${ew.customSqlSegment} ")
    JianKangPingGuInfoVo queryJianKangPingGu(@Param(Constants.WRAPPER) QueryWrapper<JianKangPingGuInfoVo> queryWrapper);

    @Select("SELECT YONGYAOZD,SHENGHUOFSZD,XUANJIAONR FROM yl_chuyuanpgyzd ${ew.customSqlSegment} ")
    JianKangZhiDaoInfoVo queryJianKangZhiDao(@Param(Constants.WRAPPER) QueryWrapper<JianKangZhiDaoInfoVo> queryWrapper);

    @Select("SELECT a.JIESUANLSH, c.ZHIFUFSMC ,c.ZHIFUFSDM,b.MINGXICWFL,b.MINGXIXMMC,a.YILIAOFKFSDM ,a.YILIAOFKFSMC ,b.MINGXIXMJE FROM yl_zhuyuanjsjl a \n" +
            "LEFT JOIN yl_zhuyuansfmx b ON a.JIESUANLSH = b.JIESUANLSH and a.YILIAOJGDM = b.YILIAOJGDM and a.YUANQUID = b.YUANQUID \n" +
            "LEFT JOIN yl_zhuyuanzfmx c ON a.JIESUANLSH = c.JIESUANLSH and a.YILIAOJGDM = c.YILIAOJGDM and a.YUANQUID = c.YUANQUID ${ew.customSqlSegment} ")
    List<FeiYongInfoVo> queryFeiYong(@Param(Constants.WRAPPER) QueryWrapper<FeiYongInfoVo> queryWrapper);


    @Select("select GEIYAOTJDM, GEIYAOTJMC, JILIANG, JILIANGDW, MEICISYSL, MEICISYSLDW, JIXINGDM, JIXINGMC, YIZHUMXMC,  YONGYAOTS yongYaoTS, MEICISYZJL, YIZHUTZRQSJ YIZHUJHJSRQSJ, " +
            " CASE " +
            "  WHEN KANGJUNYBZ=1 THEN '抗菌药物' " +
            "  WHEN JINGSHENYWBZ=1 THEN '精神药物' " +
            "  WHEN JIBENYWBZ=1 THEN '基本药物' " +
            "  WHEN SHUYEYYBZ=1 THEN '输液药物' " +
            "  WHEN DUXINGYWBZ=1 THEN '毒性药物' " +
            "  WHEN ZIZHIYBZ=1 THEN '自制药物' " +
            "  WHEN MAZUIYBZ=1 THEN '麻醉药物' " +
            " ELSE '无'  " +
            "  END AS yaoWuLX from YL_ZHUYUANYZ  ${ew.customSqlSegment} ")
    List<ZhuYuanYZVo> queryYongYao(@Param(Constants.WRAPPER) QueryWrapper<ZhuYuanYZVo> queryWrapper);


    @Select("SELECT " +
            " b.ZHUANZHENBZ," +
            " a.ZHUANZHENYY," +
            " a.ZHUANZHENRQ," +
            " a.ZHUANRUJGBH," +
            " a.ZHUANRUJGMC," +
            " a.ZHUANRUKSDM zhuanZhenKSDM," +
            " a.ZHUANRUKSMC zhuanZhenKSMC," +
            " a.ZHIDAOJY " +
            " FROM " +
            " JK_ZHUANZHENJL a" +
            " LEFT JOIN yl_ruyuanjl b ON a.ZHUYUANJZLSH = b.ZHUYUANJZLSH \n" +
            " AND a.ZHUANRUJGBH = b.YILIAOJGDM  ${ew.customSqlSegment}")
    ZhuYuanZZVO queryZhuanZhen(@Param(Constants.WRAPPER) QueryWrapper<ZhuYuanZZVO> queryWrapper);

    @Select("select JIUZHENLSH, SHOUSHUKSRQSJ, SHOUSHUJCZBM, SHOUSHUJCZMC,MAZUIFFDM  from YL_SHOUSHUJL  ${ew.customSqlSegment}")
    List<ShouShuInfoVo> queryShouShuList(@Param(Constants.WRAPPER) QueryWrapper<ShouShuInfoVo> queryWrapper);

}
